{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1875868e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list = ['Marry','Alex','Jack']\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07c99358",
   "metadata": {},
   "source": [
    "## 总结一些通用的有序数据结构的方法：\n",
    "\n",
    "### 取值：通过索引值取出对应的内容\n",
    "### 切片：通过索引值区间取出对应的一些内容\n",
    "### in 可以查看成员对象是否存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb0e8c45",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "58a3c065",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# in 可以查询数据是否存在\n",
    "\"Jack\" in 网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "52ae5290",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"张志豪\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "10e5511c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Alex', 'Jack', '张志豪', '张志豪', '张志豪', '张志豪']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list  # append后面的数据数量与enter键摁了多少次有关"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac8eb73d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# append、inser可用于增加元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "162aad7a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# insert 增加元素到某个位置# insert 增加元素到某个位置\n",
    "help(网三_name_list.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "867a67f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', '李华', 'Alex', 'Jack', '张志豪', '张志豪', '张志豪', '张志豪']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list.insert(1,\"李华\")\n",
    "网三_name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79646340",
   "metadata": {},
   "source": [
    "# remove"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8d4ba2ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Marry', '李华', 'Jack', '张志豪', '张志豪', '张志豪', '张志豪']\n"
     ]
    }
   ],
   "source": [
    "# remove 经常和   in   一起使用，先检查成员变量是否存在，然后再remove\n",
    "if \"Alex\" in 网三_name_list:\n",
    "    网三_name_list.remove(\"Alex\")\n",
    "print(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d74b6e1",
   "metadata": {},
   "source": [
    "# pop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3d1b1154",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Marry', '李华']\n"
     ]
    }
   ],
   "source": [
    "# pop\n",
    "网三_name_list.pop()\n",
    "# pop()括号里可以填入想删除的元素位置，（）默认最后一个\n",
    "print(网三_name_list)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42e3f4d1",
   "metadata": {},
   "source": [
    "# 使用while"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "a9cb266f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[18, 18, 17, 20, 20, 18, 16, 17, 20]\n"
     ]
    }
   ],
   "source": [
    "# 实践：请移除19的元素,5分钟实践尝试\n",
    "age_list = [18,19,18,19,17,20,20,18,19,16,17,20]\n",
    "while 19 in age_list:\n",
    "    age_list.remove(19)\n",
    "    \n",
    "print(age_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1c2adbf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c087e7b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "删除的数量 = age_list.count(19)\n",
    "for i in range(删除的数量):\n",
    "    if 19 in age_list:\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "965cab4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 18, 17, 20, 20, 18, 16, 17, 20]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# enmuerate枚举\n",
    "for i,v in enumerate(age_list):\n",
    "    if v == 19:\n",
    "        print(i,v)\n",
    "        age_list.pop(i)\n",
    "age_list      "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "420b26c5",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
